package mychat.util;

import java.util.regex.Pattern;

import mychat.vo.Message;
import mychat.vo.Msg;

public class MessageFactory {
	private static Pattern pattern=Pattern.compile(";");
	
	public static Message getPrivateMessagee(String from,String to,String content){
		return new Msg(from,to,Message.PRIVATE,content);
	}
//	public static Message getPrivateMessage(String from,String to){
//		return new Msg(from,to,Message.PRIVATE,"");
//	}
//	public static Message getPrivateMessage(String content){
//		return new Msg(null,null,Message.PRIVATE,content);
//	}
	public static Message getSysMessage(String content){
		return new Msg("s","a",Message.SYS,content);
	}
	public static Message getLoginMessage(String user,String password){
		return new Msg(user,"s",Message.LOGIN,password);
	}
	public static Message getExitMessage(String user){
		return new Msg(user,"s",Message.EXIT,"");
	}
	public static Message getNormalMessage(String user,String content){
		return new Msg(user,"a",Message.NORMAL,content);
	}
	public static Message getMessage(String s){
		String[] result =pattern.split(s,5);
		int type=Integer.parseInt(result[0]);
		Message msg=new Msg(result[1],result[2],type,result[4]);
		return msg;
	}
//	public static Message getNormalMessage(){
//		return new Msg(null,"a",Message.NORMAL,null);
//	}
	
}
